package com.hb.webservice;

import com.hb.domain.Spitter;
import com.hb.domain.Spittle;
import com.hb.service.SpitterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

import javax.jws.WebMethod;
import javax.jws.WebService;
import java.util.List;

// 使用 @WebService 注解所标注的类被认为 Web 服务的端点
@WebService(serviceName = "SpitterService")
// 通过继承 SpringBeanAutowiringSupport，我们可以使用 @Autowired 注解标注端点的属性，依赖就会自动注入了。
public class SpitterServiceEndpoint extends SpringBeanAutowiringSupport {
    @Autowired
    private SpitterService spitterService;

    // 使用 @WebMethod 注解所标注的方法被认为是操作
    @WebMethod
    public void addSpittle(Spittle spittle) {
        spitterService.saveSpittle(spittle);
    }

    @WebMethod
    public List<Spittle> getRecentSpittles(int spittleCount) {
        return spitterService.getRecentSpittles(spittleCount);
    }

    @WebMethod
    public List<Spittle> getSpittlesForSpitter(Spitter spitter) {
        return spitterService.getSpittlesForSpitter(spitter);
    }
}
